package com.lap.context.starter.shared;

import java.util.stream.Stream;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

@Getter
public enum LangEnum {
  EN_US("en", "en"),
  ZH_CN("zh", "zh"),
  ZH_TW("zh-tw", "zh_tw"),
  ;

  /** 数据库存储编码 */
  private final String storeLang;

  /** 请求语言编码 */
  private final String lang;

  LangEnum(String storeLang, String lang) {
    this.storeLang = storeLang;
    this.lang = lang;
  }

  public static LangEnum getStoreCode(String lang) {
    if (StringUtils.isBlank(lang)) return LangEnum.ZH_CN;

    return Stream.of(LangEnum.values())
        .filter(item -> item.lang.equals(lang))
        .findFirst()
        .orElse(LangEnum.ZH_CN);
  }
}
